//
//  CommunityViewController.m
//  wtshoppingcite
//
//  Created by TW on 15-1-26.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "CommunityViewController.h"
#import "NSString+URLEncoding.h"

@interface CommunityViewController ()<UIWebViewDelegate>

@property(nonatomic,strong)UIWebView *webView;
@property(nonatomic,strong)NSString *urlString;
@property(nonatomic,strong)UIActivityIndicatorView *activityIndicator;

@end

@implementation CommunityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    //处理导航条遮挡
//    if(Version>=7.0)
//    {
//        self.edgesForExtendedLayout = UIRectEdgeNone;
//        self.extendedLayoutIncludesOpaqueBars = NO;
//        self.modalPresentationCapturesStatusBarAppearance = NO;
//    }
    
    NSString *html = @"http://lite.m.dianping.com/k5gupESsND?uid=";
    
    if(_index == 0)
    {
        [self setTitleView:@"美食"];
        
        _urlString =[NSString stringWithFormat:@"%@%@&category=美食&longitude=%@&latitude=%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];
    }
    else if(_index == 1)
    {
        [self setTitleView:@"生活服务"];
         _urlString =[NSString stringWithFormat:@"%@%@&category=生活服务&longitude=%@&latitude=%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];

    }
    else if(_index == 2)
    {
         [self setTitleView:@"休闲娱乐"];
        _urlString =[NSString stringWithFormat:@"%@%@&category=休闲娱乐&longitude=%@&latitude=%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];
        
    }
    else if(_index == 3)
    {
         [self setTitleView:@"电影"];
        _urlString =[NSString stringWithFormat:@"%@%@&category=电影&longitude=%@&latitude=%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];

    }
    else if(_index == 4)
    {
        [self setTitleView:@"旅游"];
        _urlString =[NSString stringWithFormat:@"%@%@&category=旅游&longitude=%@&latitude%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];
    }
    else if(_index == 5)
    {
        [self setTitleView:@"精选"];
        _urlString =[NSString stringWithFormat:@"%@%@&category=精选&longitude=%@&latitude=%@&hasheader=1",html,[RegisterHelper shareHelper].registerPhoneNum,[RegisterHelper shareHelper].longitude,[RegisterHelper shareHelper].latitude];
    }
    
    
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight-64)];
    [self.view addSubview:_webView];
    
    
    [_webView setUserInteractionEnabled:YES];  //是否支持交互
    [_webView setDelegate: self];     //委托
    
    NSString *urlStr = [_urlString urlEncoding];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
    [self.view addSubview:_webView];
   
    
    _activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(10,10,20,20)];//需要在.h文件中进行声明
    
    [_activityIndicator setCenter:_webView. center];//位置
    
    [_activityIndicator   setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray];//颜色根据不同的界面自己调整
    
    [self.view  addSubview:_activityIndicator];
    
    // Do any additional setup after loading the view.
}


#pragma mark - webview
- (void)webViewDidFinishLoad:(UIWebView *)webView {
   
    _webView.hidden = NO;
     [_activityIndicator stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
     [_activityIndicator stopAnimating];
    //    [self showHUDWithString:@"网络错误！"];
    
    NSLog(@"error :%@",error);
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
     [_activityIndicator startAnimating];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}


- (void)viewWillDisappear:(BOOL)animated
{
    
    [super viewWillDisappear:animated];

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
